package com.zhaoqi.hr.entity;

import javax.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 社保记录实体
 */
@Entity
@Table(name = "social_insurances")
@EntityListeners(AuditingEntityListener.class)
public class SocialInsurance {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "worker_id", nullable = false)
    private WorkerProfile worker;
    
    @Column(nullable = false)
    private Integer year; // 缴费年份
    
    @Column(nullable = false)
    private Integer month; // 缴费月份
    
    @Column(precision = 8, scale = 2)
    private BigDecimal pensionInsurance; // 养老保险
    
    @Column(precision = 8, scale = 2)
    private BigDecimal medicalInsurance; // 医疗保险
    
    @Column(precision = 8, scale = 2)
    private BigDecimal unemploymentInsurance; // 失业保险
    
    @Column(precision = 8, scale = 2)
    private BigDecimal workInjuryInsurance; // 工伤保险
    
    @Column(precision = 8, scale = 2)
    private BigDecimal maternityInsurance; // 生育保险
    
    @Column(precision = 8, scale = 2)
    private BigDecimal housingFund; // 住房公积金
    
    @Column(precision = 8, scale = 2)
    private BigDecimal totalAmount; // 总金额
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private PaymentStatus status = PaymentStatus.PENDING;
    
    @Column
    private LocalDateTime paidAt; // 缴费时间
    
    @Column(columnDefinition = "TEXT")
    private String remark; // 备注
    
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    @LastModifiedDate
    @Column(nullable = false)
    private LocalDateTime updatedAt;
    
    /**
     * 缴费状态枚举
     */
    public enum PaymentStatus {
        PENDING("待缴费"),
        PAID("已缴费"),
        FAILED("缴费失败");
        
        private final String description;
        
        PaymentStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }

    // Getter and Setter methods
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public WorkerProfile getWorker() {
        return worker;
    }

    public void setWorker(WorkerProfile worker) {
        this.worker = worker;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public BigDecimal getPensionInsurance() {
        return pensionInsurance;
    }

    public void setPensionInsurance(BigDecimal pensionInsurance) {
        this.pensionInsurance = pensionInsurance;
    }

    public BigDecimal getMedicalInsurance() {
        return medicalInsurance;
    }

    public void setMedicalInsurance(BigDecimal medicalInsurance) {
        this.medicalInsurance = medicalInsurance;
    }

    public BigDecimal getUnemploymentInsurance() {
        return unemploymentInsurance;
    }

    public void setUnemploymentInsurance(BigDecimal unemploymentInsurance) {
        this.unemploymentInsurance = unemploymentInsurance;
    }

    public BigDecimal getWorkInjuryInsurance() {
        return workInjuryInsurance;
    }

    public void setWorkInjuryInsurance(BigDecimal workInjuryInsurance) {
        this.workInjuryInsurance = workInjuryInsurance;
    }

    public BigDecimal getMaternityInsurance() {
        return maternityInsurance;
    }

    public void setMaternityInsurance(BigDecimal maternityInsurance) {
        this.maternityInsurance = maternityInsurance;
    }

    public BigDecimal getHousingFund() {
        return housingFund;
    }

    public void setHousingFund(BigDecimal housingFund) {
        this.housingFund = housingFund;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public PaymentStatus getStatus() {
        return status;
    }

    public void setStatus(PaymentStatus status) {
        this.status = status;
    }

    public LocalDateTime getPaidAt() {
        return paidAt;
    }

    public void setPaidAt(LocalDateTime paidAt) {
        this.paidAt = paidAt;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SocialInsurance that = (SocialInsurance) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "SocialInsurance{" +
                "id=" + id +
                ", year=" + year +
                ", month=" + month +
                ", pensionInsurance=" + pensionInsurance +
                ", medicalInsurance=" + medicalInsurance +
                ", unemploymentInsurance=" + unemploymentInsurance +
                ", workInjuryInsurance=" + workInjuryInsurance +
                ", maternityInsurance=" + maternityInsurance +
                ", housingFund=" + housingFund +
                ", totalAmount=" + totalAmount +
                ", status=" + status +
                ", paidAt=" + paidAt +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                '}';
    }
}
